package com.astrob.model;

import com.astrob.naviframe.Start;

import java.util.ArrayList;

public class KeywordHandle {
	private static KeywordHandle instance = new KeywordHandle();

	public static KeywordHandle getInstance() {
		return instance;
	}

	private KeywordHandle() {
		if (Start.RUNDIR.length() <= 0) {
			Start.getInstance().checkRundir();
		}

		KeywordPATH = Start.RUNDIR + "/keyword.dat";
		load();
	}

	public ArrayList<String> mListKey = new ArrayList<String>();
	private String KeywordPATH; // Trace总目录录文件

	private void load() {
		mListKey.clear();
		ReadObjectsFromFile<String> readFile = new ReadObjectsFromFile<String>();
		readFile.onReadObjectsList(KeywordPATH, mListKey);

	}

	@SuppressWarnings("unchecked")
	public void save() {
		@SuppressWarnings("rawtypes")
		WriteObjectsToFile writeFile = new WriteObjectsToFile();
		writeFile.onWriteObjects(KeywordPATH, mListKey);
	}
	
	public void add(String strName) {
		int index = mListKey.indexOf(strName);
		if (index >= 0) {
			mListKey.remove(index);
		}		
		mListKey.add(0, strName);
		
		int size = mListKey.size();
		if (size > 20) {
			mListKey.remove(20);
		}	
	}

}
